<template>
  <l-dialog :title="$t(formTitle)" :visible.sync="formVisible" :height="700" :width="1000" @close="handleCloseForm"
    @opened="handleOpenedForm" :hasBtns="false">
    <my-form v-if="formVisible" ref="form" @close="handleCloseForm" @refresh="refresh" :onlyProgress="onlyProgress"></my-form>
  </l-dialog>
</template>

<script>
import MyForm from './form'
export default {
  components: {
    MyForm
  },
  props: {
    formTitle: {
      type: String,
      default: '进度信息'
    },
    formEdit: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      formEditRow: {},
      formVisible: false,
      activeName: 'tab0',
      onlyProgress:false,
    };
  },
  mounted() {
    this.init()
  },
  methods: {
    init() { },
    open(row = {}) {
      this.formEditRow = row
      this.activeName = row.activeName || 'tab0'
      if (this.activeName == 'tab1') {
        this.onlyProgress = true
      }
      this.formVisible = true
    },

    async handleOpenedForm(showLoading, hideLoading) {
      if (this.formEdit) {
        showLoading('加载数据中...')
        await this.$refs.form.loadFormData(this.formEditRow.id)
        this.$refs.form.activeName = this.activeName

        hideLoading()
      }
    },
    handleCloseForm() {
      this.$refs.form.resetForm()
      this.formVisible = false
    },
    refresh() {
      this.$emit('refresh')
    },

  }
};
</script>
<style lang="scss" scoped>
</style>